import java.util.Scanner;
// 定义一个循环队列类
class circularqueue {
    private int[] queue;   // 存储队列元素的数组
    private int front;  // 队列头指针
    private int rear;   // 队列尾指针
    private int size;   // 队列的当前大小
    private int length;  // 队列的最大长度
    // 构造函数，初始化队列的大小
    public circularqueue(int length) {
        this.length = length;
        this.queue = new int[length];
        this.front = 0;
        this.rear = 0; // 初始化时rear等于front
        this.size = 0;
    }
    // 判断队列是否已满
    public boolean isFull() {
        return size == length;
    }
    // 判断队列是否为空
    public boolean isEmpty() {
        return size == 0;
    }
    // 入队操作
    public void enqueue(int data) {
        if (isFull()) {
            System.out.println("队列已满");
            return;
        }
        queue[rear] = data;
        rear = (rear + 1) % length;
        size++;
        System.out.println("入队成功");
    }
    // 出队操作
    public void dequeue() {
        if (isEmpty()) {
            System.out.println("队列为空");
            return;
        }
        System.out.println(">>病人" + queue[front] + "就诊");
        front = (front + 1) % length;
        size--;
    }
    // 打印队列中的所有元素
    public void printQueue() {
        if (isEmpty()) {
            System.out.println("队列为空");
            return;
        }
        System.out.print("排队病人: ");
        if (front < rear) {
            for (int i = front; i < rear; i++) {
                System.out.print(queue[i] + " ");
            }
        } else {
            for (int i = front; i < length; i++) {
                System.out.print(queue[i] + " ");
            }
            for (int i = 0; i < rear; i++) {
                System.out.print(queue[i] + " ");
            }
        }
        System.out.println();
    }
}
public class paidui {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入病人排队队列的最大大小:");
        int length = sc.nextInt();
        circularqueue queue = new circularqueue(length);
        while (true) {
            System.out.println("1:排队 2:就诊 3:查看排队 4:不再排队,余下依次就诊 5:下班 请选择:");
            int choice = sc.nextInt(); // 读取用户输入的操作类型
            switch (choice) {
                case 1: // 排队
                    System.out.println(">>输入病历号:");
                    int number = sc.nextInt();
                    queue.enqueue(number);
                    break;
                case 2: // 就诊
                    queue.dequeue();
                    break;
                case 3: // 查看排队
                    queue.printQueue();
                    break;
                case 4: // 不再排队，余下顺序就诊
                    System.out.println(">>病人按以下顺序就诊:");
                    queue.printQueue();
                    sc.close();
                    return;
                case 5: // 下班
                    System.out.println("下班");
                    sc.close();
                    return;
                default:
                    System.out.println("无效的操作，请输入1, 2, 3, 4 或 5");
            }
        }
    }
}

